<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/14
 * Time: 14:13
 */

namespace app\common\model;


use think\Db;
use think\Model;

class StickPic extends Model
{
    protected $name = "stick_pic";

    public function getStickList($where, $filed = "*", $limit = 20, $request, $keyword) {

        if ($keyword) {
            $data = $this->alias('sp')
                ->join('stick_user su', 'sp.user_id = su.user_id', 'left')
                ->field($filed)
                ->where($where)
                ->whereOr('su.user_id', $keyword)
                ->whereOr('su.name', $keyword)
                ->whereOr('sp.id', $keyword)
                ->whereOr('su.phone', $keyword)
                ->order('sp.create_time desc')
                ->paginate($limit, false, ['query' => $request->get()]);
        } else {
            $data = $this->alias('sp')
                ->join('stick_user su', 'sp.user_id = su.user_id', 'left')
                ->field($filed)
                ->where($where)
                ->order('sp.create_time desc')
                ->paginate($limit, false, ['query' => $request->get()]);
        }

        return $data;
    }

    public function updateStatus($where, $data) {

        $res = $this->where($where)->update($data);

        return $res;
    }

    public function updateUserCoin($where) {

        $res = Db::name('stick_user')->where($where)->setInc('account_currency', 10);

        return $res;
    }
}